<template>
  <div class="box">
    <h1>品类管理</h1>
    <div>
      <el-button type="danger" @click="addshop">添加品类</el-button>
        <template>
          <el-table :data="typemain" border style="width: 100%">
            <el-table-column fixed prop="id" label="品类ID"></el-table-column>
            <el-table-column prop="name" label="名称"></el-table-column>
            <el-table-column fixed="right" label="操作">
              <template slot-scope="scope">
                 <el-button
                @click="handleClick(scope.row)"
                type="text"
                size="small"
                >查看</el-button
              >
                  <el-button
                type="text"
                size="small"
                @click="onChange(scope.row)"
                >编辑</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        
      </template>
      <!-- 分页器 -->
      <!-- <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="addDatas.pagenum"
        :page-sizes="[3, 5, 10, 100]"
        :page-size="addDatas.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination> -->
    </div>
  </div>
</template>

<script>
import { category1, gai } from "../../../http/http";
export default {
  name: "shops",
  data() {
    return {
      typemain: [],
      // addDatas: {
      //   pagenum: 1,
      //   pagesize: 5,
      // },
      // total: 0,
      typeDatas: {
        //  传递参数
        categroryId: 100001,
      },
    };
  },
  mounted() {
    this.typecontainer();
  },
  methods: {
    async typecontainer() {
      const { data: res } = await category1({
        categroryId: this.typeDatas.categroryId,
        // pageNum: this.addDatas.pagenum,
        // pageSize: this.addDatas.pagesize,
      });
      // console.log(res);
      this.typemain = res.data;
      // this.total = res.data.total;
    },
    // handleSizeChange(newValue) {
    //   // console.log(newValue);
    //   this.addDatas.pagesize = newValue;
    //   this.listContainer();
    // },
    // //pageNum
    // handleCurrentChange(newValue) {
    //   // console.log(newValue);
    //   this.addDatas.pagenum = newValue;
    //   this.listContainer();
    // },
    addshop() {
      this.$router.push({ path: "/addshop" });
    },
    handleClick(val) {
      console.log(val)
      this.$router.push(`/chashop?id=${val.id}`);
    },
    onChange(val) {
      this.$prompt("请输入修改内容", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputValue: val.name,
      })
        .then(({ value }) => {
          gai({ categoryId: val.id, categoryName: value }).then((res) => {
            category1().then((res2) => {
              this.typemain = res2.data.data;
            });
            this.$message({
              type: "success",
              message: "修改成功",
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消修改",
          });
        });
    },
  },
};
</script>

<style scoped lang="scss">
.box {
  width: 80%;
  margin-left: 20%;
}
</style>